﻿@{
    ViewBag.Title = "PublishServer";
    Layout = "~/Views/Shared/Template.cshtml";
}

<link href="css/style.css" rel="stylesheet" type="text/css">

@using Partner.MVC.Models;
@{
    var user = Session["LoginUser"] as User_Info;
}

<div style="height: 300px;width: 100%;background:url(/static/hbweb/images/me.jpg);">
    <div class="container">
        <div class="header-message">
            <img class="fl" src="http://pic.huobanchina.com/o_1bp7omfg8e821pc4bbg1u8g1ifl9.jpeg" alt="" />
            <div class="fl header-text">
                <h3 class="user-name">@user.Use_Name </h3>
                <i class="icon-fabu3 point user-namei"></i>
            </div>
            <a id="AlterPwd" style="width:85px;" data-toggle="modal" data-target="#myModal" class="fr fn-font-hover-blue change change-password">
                修改密码
            </a>
        </div>
    </div>
</div>

<div class="bgcSil">
    <div class="container">
        <div class="mt30" style="width: 100%">
            <ul id="divLeft" style="width:24%" class="nav navbar-nav"></ul>
            <div id="divContent" style="width:75%;" class="fr mb80 cont bgcWhit news-list-con">
                <div class="personal_info">
                    <h3 class="title">发布服务</h3>
                    <div class="fb_box">
                        <table class="table">
                            <tr>
                                <td><span class="c-red">服务类型：</span></td>
                                <td>

                                    <div class="form-group" style="width:250px">
                                        <select style="width:300px" class="form-control" id="S_Type"></select>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td><span>名称</span></td>
                                <td><input type="text" id="S_Name" class="form-control" style="width:300px" disabled value="@user.Use_ReallyName"></td>
                            </tr>
                            <tr>
                                <td><span>服务简介</span></td>
                                <td><input type="text" id="S_Intro" class="form-control" style="width:300px" placeholder=""></td>
                            </tr>
                            <tr>
                                <td><span>企业介绍</span></td>
                                <td><textarea class="form-control" id="S_Profile" style="width:300px;height:100px" placeholder="50字以内"></textarea></td>
                            </tr>

                            <tr>
                                <td><span>手机号</span></td>
                                <td><input type="text" id="S_Telphone" class="form-control" style="width:300px" disabled value="@user.Use_Telphone"></td>
                            </tr>
                            <tr>
                                <td>服务单价</td>
                                <td><input type="text" id="S_Price" class="form-control" style="width:300px" placeholder="元"></td>
                            </tr>
                            <tr style="height:150px">
                                <td><span>上传图片</span></td>
                                <td><input id="S_Img" type="file" /></td>
                                <td style="display:none" id="img"><img style="width:250px;height:150px" id="img12" src="" alt="" /></td>
                            </tr>
                            <tr>
                                <td><a class="btn btn-primary radius" onclick="UpLoad()">点击上传</a></td>
                            </tr>
                            <tr>
                                <td><button type="button" onclick="AddHouse_Server()" class="btn btn-danger btn-lg">确认发布</button></td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    selectLoad();
    function UpLoad() {
        $("#img").show();
        var file = document.getElementById("S_Img").files[0];
        if (!/image\/\w+/.test(file.type)) {
            alert("您选择的不是图片");
            return false;
        }
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function (e) {

            document.getElementById("img12").src = this.result;
        }
    }
    //加载下拉框
    function selectLoad() {
        $.ajax({
            type: "post",
            url: "/merchant/SelectList",
            dataType: "json",
            success: function (obj) {
                //返回 json格式字符串 [{"did":1,"dname":"研发部"}]
                //清空原有内容，添加数据
                $("#S_Type").empty();
                for (var i = 0; i < obj.length; i++) {
                    $("#S_Type").append("<option value='" + obj[i].S_TypeId + "'>" + obj[i].S_Type + "</option>");
                }
            }
        })
    }
    //实现服务添加功能
    function AddHouse_Server() { 
        var S_Type = $("#S_Type").val();
        var S_Name = $("#S_Name").val();
        var S_Intro = $("#S_Intro").val();
        var S_Profile = $("#S_Profile").val();
        var S_Telphone = $("#S_Telphone").val();
        var S_Price = $("#S_Price").val();
        var file = document.getElementById("S_Img").files[0];
        if (S_Name == "" || S_Name == null) {
            alert('填写信息不能为空')
            return
        }
        else if (S_Intro == "") {
            alert('不能为空')
            return
        }
        else if (S_Profile == "") {
            alert('不能为空')
            return
        }
        var regu = /^([1-9][0-9]*){1,3}$/
        if (!regu.test(S_Price)) {
            alert('输入格式不正确')
        }
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function (e) {
            var model = { S_Type: S_Type, S_Name: S_Name, S_Intro: S_Intro, S_Profile: S_Profile, S_Telphone: S_Telphone, S_Price: S_Price, S_Img: this.result };
            $.ajax({
                type: "post",
                url: "/Merchant/AddHouseServer",
                data: { S_Type: S_Type, S_Name: S_Name, S_Intro: S_Intro, S_Profile: S_Profile, S_Telphone: S_Telphone, S_Price: S_Price, S_Img: this.result },
                success: function (obj) {
                    if (obj > 0) {
                        alert('添加成功')
                        location.href = '/Merchant/ServerList'
                    }
                    else if (obj == 0)
                    {
                        alert('此服务您已添加，不能重复添加')
                    }
                    else {
                        alert('添加失败')
                    }
                }
            })
        }
    }
</script>

<!-- 绑定左侧导航 -->
<script>
    ParentNav();
    // 绑定根节点
    function ParentNav() {
        $.ajax({
            type: "post",
            url: "/Partner/LeftNav",
            dataType: "json",
            success: function (data) {
                var htmltab = "";
                for (var i = 0; i < data.length; i++) {
                    htmltab += "<li class=\"dropdown\"><a href=\"#\" class=\"dropdown-toggle\" data-toggle=\"dropdown\" style=\"width: 175px;font-size: 16px;\">" + data[i].Lar_Name + "</a>" + SonNav(data[i].Limit_Id) + "</li>";
                }
                $("#divLeft").append(htmltab);
            },
            error: function (err) {
                alert(err);
            }
        })
    }
    // 绑定子节点
    function SonNav(id) {
        var html1 = "";
        $.ajax({
            type: "post",
            url: "/Partner/LeftSon",
            data: { pid: id },
            dataType: "json",
            async: false,
            success: function (data) {
                var strhtml = "<ul class=\"dropdown-menu\">"
                for (var i = 0; i < data.length; i++) {
                    strhtml += "<li><a href=\"" + data[i].Limit_Url + "\">" + data[i].Limit_Name + "</a></li>"
                }
                strhtml += "</ul>";
                html1 = strhtml;
            }
        })
        return html1;
    }
</script>
<!-- 绑定左侧导航结束 -->
